﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace DataCore.XML
{
    /// <summary>Xml辅助类</summary>
    public static class XmlHelper
    {
        public static void CreateXML<T>(List<T> list, string filePath) where T : class, new()
        {

        }
        public static string XmlSerialize<T>(T obj)
        {
            // XmlWriter xmlWriter=new XmlWriter(new StreamWriter(obj.ToString()));
            using (StringWriter sw = new StringWriter())
            {
                Type t = obj.GetType();
                XmlSerializer serializer = new XmlSerializer(obj.GetType());
                serializer.Serialize(sw, obj);
                sw.Close();
                return sw.ToString();
            }
        }
        public static T Deserialize<T>(string strXML) where T : class
        {
            using (StringReader sr = new StringReader(strXML))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                return serializer.Deserialize(sr) as T;
            }
        }

    }
}
